<template>
  <div class="recharge">
    <div class="re_header">
      <top-bar :barObj="barObj"/>
      <div class="phone">
        <input type v-model="phone">
        <i class="iconfont icon-ren"></i>
      </div>
    </div>
    <div class="content">
      <div class="title">充话费</div>
      <ul>
        <li v-for="(li ,index) in phoneFeesListArr" :key="index" @click="clickLi(li)">
          <span class="money">{{li.value2}} 元</span>
          <span class="ps">{{li.value3}}PS</span>
        </li>
      </ul>
    </div>
    <div class="re_mask" v-if="isRechargeMask">
      <div class="main">
        <div class="title">
          <i class="iconfont icon-guanbi" @click="isRechargeMask=false"></i>
          确认充值
        </div>
        <p class="psNumber">PS {{currentLi.value3}}</p>
        <p class="txt">付款方式 &#x3000;&#x3000; 账户余额</p>
        <input type="password" placeholder="请输入用户密码" v-model="password">
        <div class="btn" @click="rechargeNow">立即充值</div>
      </div>
    </div>
  </div>
</template>
<script>
import topBar from "@/components/topBar";
import { telephoneFees, getTelephoneFeesList } from "@/api.js";
import { getGuid } from "@/utils/index";
import { Toast } from "mint-ui";
import { hex_md5 } from "../../utils/md5.js";

export default {
  name: "recharge",
  data() {
    return {
      barObj: {
        isBack: true,
        backVal: "商城",
        title: "游戏中心",
        isIcon: true
      },
      phone: "",
      isRechargeMask: false,
      id: localStorage.zyUserId,
      phoneFeesListArr: [],
      currentLi: {},
      password: ""
    };
  },
  components: { topBar },
  mounted() {
    this.chargeTelephoneFees();
    this.getTelephoneFees();
  },
  methods: {
    getTelephoneFees() {
      getTelephoneFeesList({
        ID: this.id,
        LoginMachine: getGuid()
      }).then(res => {
        if (res.data.Success) {
          this.phoneFeesListArr = res.data.EntityList;
        }
      });
    },
    chargeTelephoneFees({ YJELQss, YJEYhOld, MC, JYEPass } = { YJELQss: "0" }) {
      telephoneFees({
        ID: this.id,
        LoginMachine: getGuid(),
        YJELQss: YJELQss,
        YJEYhOld: YJEYhOld,
        MC: MC,
        JYEPass: JYEPass
      }).then(res => {
        if (res.data.Success) {
          if (YJELQss == 0) {
            this.phone = res.data.Content;
          } else {
            Toast({
              message: res.data.Content,
              duration: 2000
            });
          }
        } else {
          Toast({
            message: res.data.Content,
            duration: 2000
          });
        }
        this.isRechargeMask = false;
      });
    },
    clickLi(i) {
      if (this.phone.length != 11) {
        Toast({
          message: "请输入正确的手机号",
          duration: 2000
        });
        return;
      }

      this.currentLi = i;
      this.isRechargeMask = true;
    },
    rechargeNow() {
      if (!this.password) {
        Toast({
          message: "请输入密码",
          duration: 2000
        });
        return;
      }
      this.chargeTelephoneFees({
        YJELQss: "1",
        YJEYhOld: this.phone,
        MC: this.currentLi.value1,
        JYEPass: hex_md5(this.password)
      });
    }
  }
};
</script>
<style lang="stylus" scoped>
.recharge {
  .re_header {
    padding-top: 0.54rem;
    box-sizing: border-box;
    width: 100%;
    height: 2.21rem;
    background: linear-gradient(90deg, rgba(0, 174, 255, 1), rgba(0, 180, 255, 1), rgba(0, 120, 255, 1));

    .phone {
      width: 7.04rem;
      height: 1.84rem;
      line-height: 1.84rem;
      background: #FFF;
      border-radius: 0.2rem;
      margin: 20px auto;
      padding: 0 15px;
      box-sizing: border-box;
      font-size: 31px;

      input {
        width: 90%;
      }

      i {
        font-size: 31px;
        color: #FF6B00;
        float: right;
        margin-top: 6px;
      }
    }
  }

  .content {
    width: 7.04rem;
    height: 7.65rem;
    background: #FFF;
    border-radius: 0.2rem;
    margin: 70px auto;

    .title {
      line-height: 1.2rem;
      font-size: 19px;
      margin-left: 10px;
    }

    ul {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      align-items: center; /* 垂直居中 */
      justify-content: center; /* 水平居中 */

      li {
        width: 2.12rem;
        height: 1.39rem;
        border: 1px solid #898989;
        margin: 10px 2px;
        display: flex;
        flex-direction: column;
        align-items: center; /* 垂直居中 */
        justify-content: center; /* 水平居中 */
        border-radius: 0.1rem;

        .money {
          color: #898989;
          font-size: 19px;
          line-height: 0.5rem;
        }

        .ps {
          color: #898989;
          font-size: 14px;
          line-height: 0.5rem;
        }
      }
    }
  }

  .re_mask {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    position: fixed;
    left: 0;
    top: 0;

    // display: none;
    .main {
      width: 7.04rem;
      height: 8.25rem;
      background: #FFF;
      border-radius: 0.2rem;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      text-align: center;

      .title {
        width: 6.63rem;
        line-height: 1.11rem;
        border-bottom: 1px solid rgba(137, 137, 137, 0.6);
        margin: 0 auto;
        font-size: 16px;

        i {
          position: absolute;
          left: 15px;
          top: 5px;
          font-size: 18px;
        }
      }

      .psNumber {
        font-size: 33px;
        margin: 50px auto 20px auto;
      }

      .txt {
        font-size: 14px;
        color: #898989;
        margin: 20px auto;
      }

      input {
        width: 5.79rem;
        height: 0.88rem;
        background: rgba(137, 137, 137, 0.6);
        margin: 30px auto;
        border-radius: 5px;
        padding: 0 5px;
        // box-sizing: border-box;
      }

      .btn {
        width: 5.79rem;
        line-height: 1.01rem;
        background: rgba(255, 99, 44, 1);
        border-radius: 5px;
        color: #fff;
        margin: 30px auto 20px auto;
        font-size: 20px;
      }
    }
  }
}
</style>

